<?php
// no direct access
defined( '_VALID_MOS' ) or die( 'Restricted access' );

// load the html drawing class
require_once( $mainframe->getPath( 'front_html' ) );

$id		= intval(mosGetParam($_REQUEST, 'id', 0));

switch ($task){
	case 'view':
		viewPromotion( $id );
		break;

	default:
		viewPromotion( $id );
		break;	
}

function viewPromotion ( $id ){
	global $database, $mosConfig_dbprefix, $mainframe;
	
	$sql = "SELECT * FROM ".$mosConfig_dbprefix."news WHERE id=".$id;
	$database->setQuery($sql);
	$database->loadObject($row);
	
	$mainframe->setPageTitle($row->title);
	
	//get Content_id
	$sql = "SELECT * FROM ".$mosConfig_dbprefix."news_content WHERE news_id=".$row->id;
	$database->setQuery($sql);
	$lsID = $database->loadObjectList();
	$array = "(";
	for ($i=0; $i<count($lsID); $i++){
		if ($i == count($lsID)-1) $str = ""; else $str = ",";
		$array .= $lsID[$i]->content_id.$str;
	}
	$array .= ")";
	
	//show content
	$sql = "SELECT id,title,title_alias,thumbnailImage,mediumImage,largeImage,price,price_giam,muc_giam FROM ".$mosConfig_dbprefix."content WHERE state=1 AND id IN".$array." ORDER BY ordering ASC, id DESC";
	$database->setQuery($sql);
	$lsContent = $database->loadObjectList();
	
	//orther news active of this user
	$sql = "SELECT * FROM #__news WHERE user_id=".$row->user_id." AND state=1 AND id!=".$row->id." ORDER BY created DESC, id DESC";
	$database->setQuery($sql);
	$lsNewsOthersUser = $database->loadObjectList();
	
	//orther news lock of this user
	$sql = "SELECT * FROM #__news WHERE user_id=".$row->user_id." AND state=0 AND id!=".$row->id." ORDER BY created DESC, id DESC";
	$database->setQuery($sql);
	$lsNewsOthersUserBlock = $database->loadObjectList();
	
	HTML_news::viewPromotion( $row, $lsContent, $lsNewsOthersUser, $lsNewsOthersUserBlock );
}
?>